<template>
  <div class="subject" v-if="Object.keys(obj).length !== 0">
    <span>{{ obj.num1 }}</span>
    <span>+</span>
    <span>{{ obj.num2 }}</span>
    <span>=</span>
    <input v-model.number="res" type="number" />
    <button @click="complete">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      res: ''
    }
  },
  props: {
    obj: {
      type: Object,
      default() {
        return {};
      },
    },
    index: {
      type: Number,
      required: true,
    },
  },
  methods: {
    complete() {
      // console.log(this.res === this.obj.num1 + this.obj.num2 ? 1 : 2);
      this.$emit("complete", this.index, this.res === this.obj.num1 + this.obj.num2 ? 1 : 2);
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>